/*
 *                    COPYRIGHT NOTICE
 *
 *           This code is copyright protected by Freedom Inc.
 *
 *              2001-2012 All Rights Are Reserved
 */
package com.freedom.oldsong.common;

/**
 * @author steven.wang
 *
 */
public class OldsongNGException extends RuntimeException {
	

	/**
	 * @name serialVersionUID
	 * @type long
	 */
	private static final long serialVersionUID = 1L;
	
	
	/**
	 * @name DB_ERROR
	 * @type int
	 */
	public final static int DB_ERROR=10002;
	/**
	 * @name NO_SUCH_ITEM_ERROR
	 * @type int
	 */
	public final static int NO_SUCH_ITEM_ERROR=10003;
	
	
	/**
	 * @name VERSION_CONFLICT_ERROR
	 * @type int
	 */
	public final static int VERSION_CONFLICT_ERROR=30002;
	/**
	 * @name CHILD_CREATION_ERROR
	 * @type int
	 */
	public final static int CHILD_CREATION_ERROR=40001;
	/**
	 * @name DUPLICATED_NAME_ERROR
	 * @type int
	 */
	public final static int DUPLICATED_NAME_ERROR=40002;
	
	/**
	 * @name NO_ID_ERROR
	 * @type int
	 */
	public final static int NO_ID_ERROR=40020; // No id specified exception
	
	/**
	 * @name NO_PRIVILEGE_ERROR
	 * @type int
	 */
	public final static int NO_PRIVILEGE_ERROR=50001;
	/**
	 * @name NO_USER_ERROR
	 * @type int
	 */
	public final static int NO_USER_ERROR=50003;
	/**
	 * @name PWD_ERROR
	 * @type int
	 */
	public final static int PWD_ERROR=50002;
	/**
	 * @name UNKNOWN_ERROR
	 * @type int
	 */
	public final static int UNKNOWN_ERROR=99000;
	
	/**
	 * @name code
	 * @type int
	 */
	private int code;
	/**
	 * @name description
	 * @type String
	 */
	private String description;
	/**
	 * @name module
	 * @type String
	 */
	private String module;			//The module that throws the exception
	/**
	 * @name method
	 * @type String
	 */
	private String method;			//The method that throws the exception
	
	
	/**
	 * Creates a new instance of HydraNGException.
	 *
	 * @param e
	 */
	public OldsongNGException(Exception e){
		this.description=e.getMessage();
	}
	
	
	/**
	 * Creates a new instance of HydraNGException.
	 *
	 * @param e
	 * @param keyword
	 */
	public OldsongNGException(Exception e, String keyword){
		int index=e.getMessage().lastIndexOf(keyword);
		this.description = e.getMessage().substring(index <= 0 ? 0 : index+22);
	}
	
	/**
	 * Creates a new instance of HydraNGException.
	 *
	 * @param des
	 */
	public OldsongNGException(String des){
		this.description=des;
	}
	
	/**
	 * Constructs a new class with the given error code 
	 * and error description
	 * @param error code
	 * @param error description
	 */
	
	/**
	 * Creates a new instance of HydraNGException.
	 *
	 * @param code
	 * @param des
	 */
	public OldsongNGException(int code,String des){
		this.code=code;
		this.description=des;
	}
	
	/**
	 * Constructor. Constructs the class by mapping  
	 * error code from sql server.
	 * @param sqlErrorCode 
	 */
	
	/**
	 * Creates a new instance of HydraNGException.
	 *
	 * @param errorcode
	 * @param message
	 * @param module
	 * @param method
	 */
	public OldsongNGException(int errorcode,String message, String module, String method){
		this.method=method;
		this.module=module;
		this.code=errorcode-10000;
		this.description=message;
	}
	
	/**
	 * @name getCode
	 *
	 * @return    
	 * int     
	 * @throws 
	*/
	public int getCode() {
		return code;
	}
	/**
	 * @name setCode
	 *
	 * @param code    
	 * void     
	 * @throws 
	*/
	public void setCode(int code) {
		this.code = code;
	}
	/**
	 * @name getDescription
	 *
	 * @return    
	 * String     
	 * @throws 
	*/
	public String getDescription() {
		return description;
	}
	/**
	 * @name setDescription
	 *
	 * @param description    
	 * void     
	 * @throws 
	*/
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * @name getModule
	 *
	 * @return    
	 * String     
	 * @throws 
	*/
	public String getModule() {
		return module;
	}

	/**
	 * @name setModule
	 *
	 * @param module    
	 * void     
	 * @throws 
	*/
	public void setModule(String module) {
		this.module = module;
	}

	/**
	 * @name getMethod
	 *
	 * @return    
	 * String     
	 * @throws 
	*/
	public String getMethod() {
		return method;
	}

	/**
	 * @name setMethod
	 *
	 * @param method    
	 * void     
	 * @throws 
	*/
	public void setMethod(String method) {
		this.method = method;
	}
}
